<template>
	<el-container>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="list.apiObj" row-key="id" stripe>
	            <el-table-column label="业务" prop="remark" width="150"></el-table-column>
				<el-table-column label="配置值" prop="biz_value" width="250">
					<template #default="scope">
						<p style="max-height: 200px;" v-if="scope.row.type != 2">{{scope.row.biz_value}}</p>
						<img style="max-height: 200px;" :src="scope.row.biz_value" v-else />
					</template>
				</el-table-column>

				<el-table-column label="操作" fixed="right" align="right" width="300">
					<template #default="scope">
						<el-button type="primary" plain size="small" @click="table_edit(scope.row)">编辑</el-button>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>

	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>


</template>

<script>
	import saveDialog from './save'

	export default {
		name: 'configureList',
		components: {
			saveDialog,
		},
		data() {
			return {
				dialog:{
					save: false,
				},
				list: {
					apiObj: this.$API.system.configure.list
				},
				selection: []
			}
		},
		mounted() {

		},
		methods: {
			//窗口编辑
			table_edit(row){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open('edit').setData(row)
				})
			},

			//本地更新数据
			handleSaveSuccess(data, mode){
				//为了减少网络请求，直接变更表格内存数据
				if(mode=='add'){
					this.$refs.table.unshiftRow(data)
				}else if(mode=='edit'){
					this.$refs.table.updateKey(data)
				}

				//当然也可以暴力的直接刷新表格
				// this.$refs.table.refresh()
			}
		}
	}
</script>

<style>
</style>
